package com.mls.fivedistrict.listener;

import com.mls.fivedistrict.event.WithdrawEvent;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * Created by chenxiuxiang on 2018/5/9.
 */
@Component
@Slf4j
public class WithdrawListener {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Async
    @TransactionalEventListener
    public void withdrawListener(WithdrawEvent event) {
        try {
            rabbitTemplate.convertAndSend("extractExchange", "extractGD", event.getJsonStr());
        } catch (Exception e) {
            log.error("消息入列失败");
        }
    }
}
